#!/usr/bin/env python
# Copyright (c) 2009-9 Angelipin(angelipin@126.com). All rights reserved

import os
import platform
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *


__version__ = "1.0.0"


class FreeFtp(QMainWindow):

	def __init__(self,parent=None):
		super(FreeFtp,self).__init__(parent)
		
		self.speed = 0             #file transfer speed
		self.setWindowTitle("Free Ftp")        #set windows title
		
		#set menu
		#set menu
		#set tool bar
		#set tool bar
		quickConnectAction = self.createAction("&Connect",self.quickConnect,"Ctrl+C","quickconnect","Quick connect to FTP server")
		quitAction = self.createAction("&Quit",self.close,"Ctrl+Q","quit","Close the application")
		self.FTPMenu = self.menuBar().addMenu("&FTP")
		self.addActions(self.FTPMenu,(quickConnectAction,quitAction))


		self.localListWidget = QListWidget()
		self.localListWidget.addColumn(self.__tr("Icon"))
		self.localListWidget.addColumn("FileName")
		self.localListWidget.addColumn("Size")
		self.localListWidget.addColumn("Type")
		
		self.setCentralWidget(self.localListWidget)

		
		self.sizeLabel = QLabel()
		self.sizeLabel.setFrameStyle(QFrame.StyledPanel|QFrame.Sunken)

		status = self.statusBar()
		status.setSizeGripEnabled(False)
		status.addPermanentWidget(self.sizeLabel)
		self.sizeLabel.setText("Speed:      %d   Time:       " % self.speed)
		status.showMessage("Ready",50000)
		
		settings = QSettings()
		size = settings.value("MainWindow/Size",QVariant(QSize(600,500))).toSize()
		self.resize(size)
		position = settings.value("MainWindo/Position",QVariant(QPoint(0,0))).toPoint()
		self.move(position)


	def __tr(self,s,c=None):
		
		return qApp.translate("TestAppUI",s,c)
		
	def quickConnect(self):
		pass

	def createAction(self,text,slot=None,shortcut=None,icon=None,tip=None,checkable=False,signal="triggered()"):
		action = QAction(text,self)
		if icon is not None:
			action.setIcon(QIcon(":/%s.png" % icon))
		if shortcut is not None:
			action.setShortcut(shortcut)
		if tip is not None:
			action.setToolTip(tip)
			action.setStatusTip(tip)
		if slot is not None:
			self.connect(action,SIGNAL(signal),slot)
		if checkable:
			action.setCheckable(True)
		return action

	def addActions(self,target,actions):
		for action in actions:
			if action is None:
				target.addSeparator()
			else:
				target.addAction(action)

def main():
	app = QApplication(sys.argv)
	app.setOrganizationName("Angelipin")
	app.setApplicationName("FreeFtp")
	form = FreeFtp()
	form.show()
	app.exec_()


main()
